home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
SETFILE.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
8KB
|
332 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*/
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
/*******************************************************************
*
* Function SetFile
*
* PathName Callback function
*
* usage SetFile [options] [names]
*
* L Locked = Bit 0 of ioFlAttrib
* V Invisible = Bit 14 of finder flags
* B Bundle = Bit 13 of finder flags
* S System = Bit 12 of finder flags
* I Inited = Bit 8 of finder flags
* D Desktop = Bit 0 of finder flags
* M Shared = Bit 6 of finder flags
* A Always switch = Bit 5 of finder flags
*
* No INITS = Bit 7 of finder flags
* BOZO = Bit 11 of finder flags
* Changed = Bit 10 of finder flags
*
*******************************************************************/
#define fLocked 1
#define fSystem 0x1000
#define fInited 0x0100
#define fShared 0x0040
#define fSwtLan 0x0020
#define fNoInit 0x0080
#define fBusy 0x0400
#define fChange 0x0200
int16 forceAttr,
attrLocked,
attrInvis,
attrBundle,
attrSystem,
attrInited,
attrDeskTop,
attrShared,
attrSwitch;
#define attrType (**MyShell).Proc[ProcID].long0
#define attrCrea (**MyShell).Proc[ProcID].long1
char attrStr[ 32 ];
ScanAttrStr()
{
char *cp = attrStr;
while( *cp )
{
switch( *cp )
{
case 'l' :
case 'L' : attrLocked = (*cp == 'L'); break;
case 'v' :
case 'V' : attrInvis = (*cp == 'V'); break;
case 'b' :
case 'B' : attrBundle = (*cp == 'B'); break;
case 's' :
case 'S' : attrSystem = (*cp == 'S'); break;
case 'i' :
case 'I' : attrInited = (*cp == 'I'); break;
case 'd' :
case 'D' : attrDeskTop = (*cp == 'D'); break;
case 'm' :
case 'M' : attrShared = (*cp == 'M'); break;
case 'a' :
case 'A' : attrSwitch = (*cp == 'A'); break;
}
cp++;
}
}
GetAttr( int16 fdrFlags, int16 ioFlAttrib )
{
attrLocked = (ioFlAttrib & fLocked);
attrInvis = (fdrFlags & fInvisible);
attrBundle = (fdrFlags & fHasBundle);
attrSystem = (fdrFlags & fSystem);
attrInited = (fdrFlags & fInited);
attrDeskTop = (fdrFlags & fOnDesk);
attrShared = (fdrFlags & fShared);
attrSwitch = (fdrFlags & fSwtLan);
}
DoBit( int16 *iptr, int16 bit, int16 on )
{
int16 val = *iptr, mask;
mask = 0x0001 << bit;
if( on )
*iptr |= mask;
else
*iptr &= (mask ^ 0xFFFF);
}
SetAttr( FInfo *ioFlFndrInfo, OsType SAattrType, OsType SAattrCrea )
{
DoBit( &(ioFlFndrInfo->fdFlags), 14, attrInvis );
DoBit( &(ioFlFndrInfo->fdFlags), 13, attrBundle );
DoBit( &(ioFlFndrInfo->fdFlags), 12, attrSystem );
DoBit( &(ioFlFndrInfo->fdFlags), 8, attrInited );
DoBit( &(ioFlFndrInfo->fdFlags), 0, attrDeskTop );
DoBit( &(ioFlFndrInfo->fdFlags), 6, attrShared );
DoBit( &(ioFlFndrInfo->fdFlags), 5, attrSwitch );
if( SAattrType )
ioFlFndrInfo->fdType = SAattrType;
if( SAattrCrea )
ioFlFndrInfo->fdCreator = SAattrCrea;
}
void SetFileCallBack( WHandle ShellWh, int16 ProcID,
char *path, char *last,
pathType what, int16 vRefNum, int32 dirID )
{
HFileInfo pb;
OSErr err;
char str[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( what == pathIsFile )
{
strcpy( str, last );
CtoPstr( str );
pb.ioCompletion = NULL;
pb.ioNamePtr = (StringPtr) str;
pb.ioVRefNum = vRefNum;
pb.ioFDirIndex = 0;
pb.ioDirID = dirID;
err = PBHGetFInfo( &pb, FALSE );
if( err )
{
procPrintf( ShellWh, ProcID, "setfile : can't get info for %s (%d)\n",
last, err );
return;
}
GetAttr( pb.ioFlFndrInfo.fdFlags, pb.ioFlAttrib );
if( forceAttr )
ScanAttrStr();
SetAttr( (FInfo *) &(pb.ioFlFndrInfo), attrType, attrCrea );
if( forceAttr && attrLocked )
err = HSetFLock( vRefNum, dirID, str );
else if( forceAttr && !attrLocked )
err = HRstFLock( vRefNum, dirID, str );
if( !err )
err = HSetFInfo( vRefNum, dirID, str, (FInfo *) &(pb.ioFlFndrInfo) );
if( err )
{
procPrintf( ShellWh, ProcID, "setfile : can't set info for %ps (%d)\n",
str, err );
return;
}
}
}
void SetFileAttr( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) SetFileCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoSETFILE( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
forceAttr = FALSE;
attrType = 0L;
attrCrea = 0L;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'a' : /* Attributes */
GetArgv( ShellWh, ProcID, ++i, attrStr );
forceAttr = TRUE;
break;
case 't' : /* Type */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
attrType = StrToType( temp );
}
break;
case 'c' : /* Creator */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
attrCrea = StrToType( temp );
}
break;
}
}
for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument == '-' )
i++;
else
SetFileAttr( ShellWh, ProcID, argument );
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}